// SocketLayer.h: interface for the CSocketLayer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SOCKETLAYER_H__47120FA4_A39D_4A1F_BC4C_BF86189A8020__INCLUDED_)
#define AFX_SOCKETLAYER_H__47120FA4_A39D_4A1F_BC4C_BF86189A8020__INCLUDED_

#include "StatusFeedback.h"
#include "SocketLayerEvents.h"
#include "Exceptions.h"

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CSocketLayer : public CAsyncSocket
{
private:
	BOOL m_bWsInited;
	BOOL m_bConnected;
	
	CStatusFeedback *m_pStatusFeedback;
	CSocketLayerEvents *m_pEvent;

	CArray<char, char> m_sendBuffer;
	int m_nBytesSent;
    int m_nBytesBufferSize;


	//SOCKET m_socket;
	
	//void onSocketClosed();
	void setStatus(const CString& status);
	void checkInitWs();
	void doSend();

protected:
	virtual void OnReceive(int nErrorCode);
	virtual void OnSend(int nErrorCode);
	virtual void OnClose(int nErrorCode);
	virtual void OnConnect(int nErrorCode);
	
public:
	//char ReadChar();
	void SendChar(char c);
	//const CString& ReadText(int desiredLen = 0);
	void SendText(const CString& text);
	void SendBuf(const char* buf, int len);

	void RegisterEvent(CSocketLayerEvents *pEvent);
	BOOL IsConnected();
	void Connect(const CString& host, int port);
	void Disconnect();

public:
	CSocketLayer();
	virtual ~CSocketLayer();

};

#endif // !defined(AFX_SOCKETLAYER_H__47120FA4_A39D_4A1F_BC4C_BF86189A8020__INCLUDED_)
